package com.bocek.chakmapoint.view.toolbar;

import javax.swing.JColorChooser;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;

import com.bocek.chakmapoint.controller.SlideEditController;

import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;

public class LineToolbarView extends JPanel {
	private static final long serialVersionUID = 4760923138797116230L;
	private static LineToolbarView instance = null;
	
	public static LineToolbarView getInstance() {
		
		if (instance == null) {
			instance = new LineToolbarView();
		}
		return instance;
	}

	/**
	 * Create the panel.
	 */
	private LineToolbarView() {
		
		JLabel lblToolLine = new JLabel("Tool: Line     ");
		add(lblToolLine);
		
		JLabel lblNewLabel = new JLabel("Thickness:");
		add(lblNewLabel);
		
		JComboBox comboBox = new JComboBox();
		comboBox.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				SlideEditController.getInstance().setThickness(Integer.parseInt( (String) e.getItem()));
			}
		});
		comboBox.setModel(new DefaultComboBoxModel(new String[] {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}));
		add(comboBox);
		comboBox.setSelectedIndex(SlideEditController.getInstance().getSelectedItemThickness() + 1);
		
		JButton btnSelectColor = new JButton("Select Color");
		btnSelectColor.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Color color = JColorChooser.showDialog(null,
						"Choose Line Color", SlideEditController.getInstance().getSelectedItemColor());

				if (color != null)
					SlideEditController.getInstance().setColor(color);
			}
		});
		add(btnSelectColor);

	}

}
